<%@page contentType="text/html;charset=utf-8" pageEncoding="UTF-8" %>
<%@page import="org.ipo.mm.web.util.ConstantManager, java.util.Collection, org.ipo.mm.web.util.security.SecurityManager, org.ipo.mm.web.util.pager.AbstractPager, java.util.Vector" %>
<%@taglib prefix="l" uri="http://struts.apache.org/tags-logic" %>
<%@taglib prefix="b" uri="http://struts.apache.org/tags-bean" %>
<%@taglib prefix="h" uri="http://struts.apache.org/tags-html"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%	String readOnlyStr = (String) session.getAttribute("readOnly");%>

<script type="text/javascript">
    function encode(string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";
 
        for (var n = 0; n < string.length; n++) {
 
            var c = string.charCodeAt(n);
 
            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
 
        }
 
        return utftext;
    }
</script>


<%
            Collection<Integer> privileges = (Collection<Integer>) request.getSession().getAttribute(ConstantManager.SESSION_USER_PRIVILEGES);
%>


<h1>
    <% if (readOnlyStr.equals("true")) {%>
    <b:message key="representatives_show_read_mode"/>
    <%} else {%>
    <b:message key="representatives_show_edit_mode"/>
    <%}%>
</h1>

<table id="reprListTable" class="display">
    <thead>
        <tr>

            <th><b:message key="repr_name"/></th>
            <th><b:message key="gen_email"/></th>
            <th><b:message key="gen_telephone"/></th>
            <th><b:message key="gen_fax"/></th>
            <th><b:message key="repr_function"/></th>
            <th><b:message key="repr_inst"/></th>        
            <th class="do-not-sort"><b:message key="meetings_meetings"/></th>
            <%if (readOnlyStr.equals("false")) {%>
            <th class="do-not-sort"><b:message key="gen_action"/></th>
            <%}%>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <!--
			<th><b:message key="index"/></th>
        <th><b:message key="repr_name"/></th>
        <th><b:message key="gen_email"/></th>
        <th><b:message key="gen_telephone"/></th>
        <th><b:message key="gen_fax"/></th>
        <th><b:message key="repr_function"/></th>
        <th><b:message key="repr_inst"/></th>
			<th><b:message key="meetings_meetings"/></th>
            <%if (readOnlyStr.equals("false")) {%>
			<th><b:message key="gen_action"/></th>
            <%}%>
            -->

            <th><input type="text" class="search_init" /></th>
            <th><input type="text" class="search_init" /></th>
            <th><input type="text" class="search_init" /></th>
            <th><input type="text"  class="search_init" /></th>
            <th><input type="text"  class="search_init" /></th>
            <th><input type="text" class="search_init" /></th>
            <th></th>
            <%if (readOnlyStr.equals("false")) {%>
            <th></th>
            <%}%>

        </tr>
    </tfoot>
    <tbody>
        <l:empty name="REP_SEARCH_RESULTS">            
            <tr>
                <td colspan="8">
                    <div class="centeredinfo">
                        <img src="<%= request.getContextPath()%>/icons/info.png" align="top"/>
                        <b:message key="gen_no_search_results"/>
                    </div>
                </td>
            </tr>
        </l:empty>

        <l:iterate id="repr" name="REP_SEARCH_RESULTS" scope="request">
            <tr>

                <td>   
                    <%
					if (privileges.contains(SecurityManager.EDIT_REPRESENTATIVE_PRIVILEGE) &&  (readOnlyStr.equals("false"))) {
					%>
                    <span>
                        <p id=reprDetail${repr.id} class="link"
                           onclick="getHtmlAjax('<%= request.getContextPath()%>/protected/dispatch.do?method=showUpdateReprForm&rid=${repr.id}','#reprDialog','#reprForm');" >
                            <b:write name="repr" property="firstName"/>
                            <b:write name="repr" property="lastName"/>
                        </p>               
                    </span>
                    <% } else {%>
					<span>
                        <p class="link"
                           onclick="getHtmlAjax('<%= request.getContextPath()%>/protected/dispatch.do?method=viewReprForm&rid=${repr.id}','#reprDialog','#reprForm');" >
                            <b:write name="repr" property="firstName"/>
                            <b:write name="repr" property="lastName"/>
                        </p>   
                    </span>
                    <%}%>
                </td>
                <td>
                    <h:link href="mailto:${repr.email}">
                        ${repr.email}
                    </h:link>

                </td>
                <td><span><b:write name="repr" property="telephone"/></span></td>
                <td><span><b:write name="repr" property="fax"/></span></td>
                <td><span><b:write name="repr" property="function"/></span></td>
                <td><span>${repr.institution.name}</span></td>
                <!--<td><b:write name="repr" property="note"/></td>-->
                <td>
                    <h:link action="/protected/meeting_search">
                        <h:param name="rid"  value="${repr.id}"/>
                        <h:param name="readOnly"  value="true"/>
                        <b:message key="repr_find_meetings"/>
                    </h:link>
                </td>
                <%if (readOnlyStr.equals("false")) {%>
                <td>
                    <%if (privileges.contains(SecurityManager.DELETE_REPRESENTATIVE_PRIVILEGE)) {%>
                    <h:link styleClass="delete" action="/protected/dispatch?method=deleteRepresentative"
                            paramId="rid" paramName="repr" paramProperty="id" 
                            onclick="return confirm('Are you sure you want to delete this item?/Da li ste sigurni da zelite da izbrisete ovaj entitet?')">
                        <b:message key="gen_delete"/>
                    </h:link>
                    <%}%>
                </td>
                <%}%>
            </tr>

        </l:iterate>
    </tbody>
</table>


<div id="reprDialog" class="dialog"></div>
<div id ="messageregion"></div>

<script type="text/javascript">
    function cancelForm(){
        $(".dialog").dialog('close');
    }
</script>

